<# # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Endpoint Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description: Script is designed to delete computer & user based temp files available on a machine except the mentioned extension format # Configuration Type - COMPUTER # Note: Extension need to be hardcoded inside the script at @('.scr', '.jpg') #> # Extract Username $name = (Get-WMIObject -ClassName Win32_ComputerSystem).Username $username = $name.split("\")[1] # Define paths $windowsTempPath = "C:\Windows\Temp" $localTempPath = "C:\Users\$username\AppData\Local\Temp" # Function to delete files while excluding specific extensions function Remove-ExcludedItems { param ( [string]$path, [string[]]$excludeExtensions ) Get-ChildItem -Path $path -Recurse -Force | Where-Object { $_.PSIsContainer -or ($excludeExtensions -notcontains $_.Extension.ToLower()) } | Remove-Item -Recurse -Force } # Delete C:\Windows\Temp folder excluding .scr and .jpg files Remove-ExcludedItems -path $windowsTempPath -excludeExtensions @('.scr', '.jpg') #The values need to be hardcoded here # Delete C:\Users\$username\AppData\Local\Temp folder excluding .scr and .jpg files Remove-ExcludedItems -path $localTempPath -excludeExtensions @('.scr', '.jpg') #The values need to be hardcoded here